from rest_framework import serializers, views, status
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from apps.app01.models import Address

# Address 序列化器
class AddressSerializer(serializers.ModelSerializer):
    # authentication_classes = []
    class Meta:
        model = Address
        fields = ['id', 'name', 'phone', 'dz']

# 返回地址信息的视图
class AddressListView(views.APIView):
    def get(self, request):
        user_id = request.user['user_id']  # 获取当前用户 ID
        addresses = Address.objects.filter(user_id=user_id)  # 筛选属于该用户的地址
        serializer = AddressSerializer(addresses, many=True)
        return Response(serializer.data, status=status.HTTP_200_OK)